home *** CD-ROM | disk | FTP | other *** search
/ Startware 8 / startware 8.iso / html / link.java < prev    next >
Encoding:
Java Source  |  1997-01-25  |  3.4 KB  |  101 lines

  1. /*
  2.  
  3.  
  4.  
  5. link.java
  6.  
  7.  
  8.  
  9. This is an applet that creates a drop down menu with links to sites that you specify in the param tags of you html file. 
  10.  
  11.  
  12.  
  13. Created: 6/13/96
  14.  
  15.  
  16.  
  17. By: Darryl Stoflet
  18.  
  19.  
  20.  
  21. dstoflet@calweb.com
  22.  
  23.  
  24.  
  25. http://www.calweb.com/~dstoflet
  26.  
  27.  
  28.  
  29. Thanks Suresh Srinivasan (suresh@thomtech.com) for the color parameters.
  30.  
  31.  
  32.  
  33. */
  34.  
  35.  
  36.  
  37. import java.util.*;
  38.  
  39.  
  40.  
  41. import java.net.*;
  42.  
  43.  
  44.  
  45. import java.awt.*;
  46.  
  47.  
  48.  
  49. import java.applet.Applet;
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. public class link extends Applet{
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.     public int number;
  74.  
  75.  
  76.  
  77.     public Vector urls = new Vector();
  78.  
  79.  
  80.  
  81.     public Vector names = new Vector();
  82.  
  83.  
  84.  
  85.     public URL theURL = null;
  86.  
  87.  
  88.  
  89.     String at;
  90.  
  91.  
  92.  
  93.     StringTokenizer st;
  94.  
  95.  
  96.  
  97.     StringTokenizer str;
  98.  
  99.  
  100.  
  101.     String targetFrame;
  102.  
  103.  
  104.  
  105.     Color bgColor;
  106.  
  107.  
  108.  
  109.     String s;
  110.  
  111.  
  112.  
  113.     String rgbDelimiter = ":,.";
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.    public void init() {
  122.  
  123.  
  124.  
  125.        s = getParameter("bgColor");
  126.  
  127.  
  128.  
  129.     if (s != null) st = new StringTokenizer(s, rgbDelimiter);
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.     if (s == null)
  138.  
  139.  
  140.  
  141.         bgColor = Color.lightGray;
  142.  
  143.  
  144.  
  145.     else if (s.equalsIgnoreCase("red"))
  146.  
  147.  
  148.  
  149.         bgColor = Color.red;
  150.  
  151.  
  152.  
  153.     else if (s.equalsIgnoreCase("blue"))
  154.  
  155.  
  156.  
  157.         bgColor = Color.blue;
  158.  
  159.  
  160.  
  161.     else if (s.equalsIgnoreCase("green"))
  162.  
  163.  
  164.  
  165.         bgColor = Color.green;
  166.  
  167.  
  168.  
  169.     else if (s.equalsIgnoreCase("yellow"))
  170.  
  171.  
  172.  
  173.         bgColor = Color.yellow;
  174.  
  175.  
  176.  
  177.     else if (s.equalsIgnoreCase("white"))
  178.  
  179.  
  180.  
  181.         bgColor = Color.white;
  182.  
  183.  
  184.  
  185.     else if (s.equalsIgnoreCase("orange"))
  186.  
  187.  
  188.  
  189.         bgColor = Color.orange;
  190.  
  191.  
  192.  
  193.     else if (s.equalsIgnoreCase("cyan"))
  194.  
  195.  
  196.  
  197.         bgColor = Color.cyan;
  198.  
  199.  
  200.  
  201.     else if (s.equalsIgnoreCase("magenta"))
  202.  
  203.  
  204.  
  205.         bgColor = Color.magenta;
  206.  
  207.  
  208.  
  209.                 else if (s.equalsIgnoreCase("black"))
  210.  
  211.  
  212.  
  213.         bgColor = Color.black;
  214.  
  215.  
  216.  
  217.     else if (st.countTokens() == 3) {
  218.  
  219.  
  220.  
  221.         Integer r = new Integer(st.nextToken());
  222.  
  223.  
  224.  
  225.         Integer g = new Integer(st.nextToken());
  226.  
  227.  
  228.  
  229.         Integer b = new Integer(st.nextToken());
  230.  
  231.  
  232.  
  233.         bgColor = new Color(r.intValue(), g.intValue(), b.intValue());
  234.  
  235.  
  236.  
  237.     } else
  238.  
  239.  
  240.  
  241.         bgColor = Color.lightGray; 
  242.  
  243.  
  244.  
  245.         String input_location = getParameter("target");
  246.  
  247.  
  248.  
  249.  
  250.          if(input_location != null) {
  251.  
  252.  
  253.  
  254.  
  255.                 targetFrame = input_location;
  256.  
  257.  
  258.  
  259.  
  260.           }
  261.  
  262.  
  263.  
  264.  
  265.            else{
  266.  
  267.  
  268.  
  269.  
  270.                  targetFrame = "_parent";
  271.  
  272.  
  273.  
  274.  
  275.            }
  276.  
  277.  
  278.  
  279.        String input_number = getParameter("number");
  280.  
  281.  
  282.  
  283.        number = Integer.parseInt(input_number);
  284.  
  285.  
  286.  
  287.        Choice theLinks = new Choice();
  288.  
  289.  
  290.  
  291.        for(int i = 0; i <= number; i++){
  292.  
  293.  
  294.  
  295.              at = getParameter("link" + i);
  296.  
  297.  
  298.  
  299.              str = new StringTokenizer(at, "\\");
  300.  
  301.  
  302.  
  303.              names.addElement(new String(str.nextToken())); 
  304.  
  305.  
  306.  
  307.              urls.addElement(new String(str.nextToken())); 
  308.  
  309.  
  310.  
  311.              theLinks.addItem((String)names.elementAt(i));
  312.  
  313.  
  314.  
  315.        }
  316.  
  317.  
  318.  
  319.        add(theLinks);
  320.  
  321.  
  322.  
  323.        setBackground(bgColor);
  324.  
  325.  
  326.  
  327.    }
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.    public boolean action(Event evt, Object arg){
  336.  
  337.  
  338.  
  339.         if(evt.target instanceof Choice){
  340.  
  341.  
  342.  
  343.           String site = (String)arg;
  344.  
  345.  
  346.  
  347.              for(int n = 0; n <= number; n++){
  348.  
  349.  
  350.  
  351.                 if(site.equals((String)names.elementAt(n))){
  352.  
  353.  
  354.  
  355.                     try{theURL = new URL((String)urls.elementAt(n));}
  356.  
  357.  
  358.  
  359.                     catch(MalformedURLException e) {
  360.  
  361.  
  362.  
  363.                     System.out.println("Bad URL");}
  364.  
  365.  
  366.  
  367.                     getAppletContext().showDocument(theURL,targetFrame);
  368.  
  369.  
  370.  
  371.                 }
  372.  
  373.  
  374.  
  375.              }
  376.  
  377.  
  378.  
  379.          } 
  380.  
  381.  
  382.  
  383.     return true; 
  384.  
  385.  
  386.  
  387.     }
  388.  
  389.  
  390.  
  391. }
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.